import type { GlobConfig } from '#/config';
import { getAppEnvConfig } from '@/utils/env';

export const useGlobSetting = (): Readonly<GlobConfig> => {
  const {
    VITE_GLOB_APP_TITLE,
    VITE_GLOB_API_AUTHENTICATION_SCHEME,
    VITE_GLOB_API_URL,
    VITE_GLOB_API_URL_PREFIX,
    VITE_GLOB_UPLOAD_URL,

    VITE_GLOB_SIGNIN_URL,
    VITE_GLOB_SIGNALR_URL,
    VITE_GLOB_FILES_URL,
    VITE_GLOB_SIGNALR_URL_PREFIX,
    VITE_GLOB_FILES_URL_PREFIX,
  } = getAppEnvConfig();

  /** 采用全局配置 Take global configuration */
  const glob: Readonly<GlobConfig> = {
    title: VITE_GLOB_APP_TITLE,
    authenticationScheme: VITE_GLOB_API_AUTHENTICATION_SCHEME,
    apiUrl: VITE_GLOB_API_URL,
    shortName: VITE_GLOB_APP_TITLE.replace(/\s/g, '_').replace(/-/g, '_'),
    urlPrefix: VITE_GLOB_API_URL_PREFIX,
    uploadUrl: VITE_GLOB_UPLOAD_URL,

    signinUrl: VITE_GLOB_SIGNIN_URL,
    signalrUrl: VITE_GLOB_SIGNALR_URL,
    filesUrl: VITE_GLOB_FILES_URL,
    signalrPrefix: VITE_GLOB_SIGNALR_URL_PREFIX,
    filesPrefix: VITE_GLOB_FILES_URL_PREFIX,
  };
  return glob as Readonly<GlobConfig>;
};
